package kr.pe.johnkim.pushchat.mobile.dao;

import kr.pe.johnkim.pushchat.mobile.domain.PushChatMember;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 13. 6. 12.
 */
@Repository
public class PushChatMemberDaoImpl extends SqlSessionDaoSupport implements PushChatMemberDao {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(PushChatMemberDaoImpl.class);

    /**
     * 멤버 아이디 중복 확인을 한다.
     *
     * @param pushChatMember
     * @return
     */
    @Override
    public PushChatMember selectDuplicationMember(PushChatMember pushChatMember) {
        logger.info("selectDuplicationMember");
        return (PushChatMember)this.getSqlSession().selectOne("PUSHCHAT_MEMBER.selectDuplicationMember", pushChatMember);
    }

    /**
     * 멤버를 등록 한다.
     *
     * @param pushChatMember
     */
    @Override
    public void registerMember(PushChatMember pushChatMember) {
        logger.info("registerMember");
        this.getSqlSession().insert("PUSHCHAT_MEMBER.registerMember", pushChatMember);
    }

    /**
     * 멤버 로그인을 한다.
     *
     * @param pushChatMember
     * @return
     */
    @Override
    public PushChatMember login(PushChatMember pushChatMember) {
        logger.info("login");
        return (PushChatMember)this.getSqlSession().selectOne("PUSHCHAT_MEMBER.login", pushChatMember);
    }

    /**
     * 멤버 목록을 가져 온다.
     *
     * @param pushChatMember
     * @return
     */
    @Override
    public List<PushChatMember> selectMemberList(PushChatMember pushChatMember) {
        logger.info("selectMemberList");
        return this.getSqlSession().selectList("PUSHCHAT_MEMBER.selectMemberList", pushChatMember);
    }

    /**
     * 사용자의 GCM / APNS Device Token 을 업데이트 한다.
     *
     * @param pushChatMember
     */
    @Override
    public void updateRegistrationId(PushChatMember pushChatMember) {
        logger.info("updateRegistrationId");
        this.getSqlSession().update("PUSHCHAT_MEMBER.updateRegistrationId", pushChatMember);
    }

    /**
     * 멤버 정보를 가져 온다.
     *
     * @param pushChatMember
     * @return
     */
    @Override
    public PushChatMember selectMemberInformation(PushChatMember pushChatMember) {
        logger.info("selectMemberInformation");
        return (PushChatMember)this.getSqlSession().selectOne("PUSHCHAT_MEMBER.selectMemberInformation", pushChatMember);
    }

    /**
     * 멤버를 검색 한다.
     *
     * @param pushChatMember
     * @return
     */
    @Override
    public List<PushChatMember> selectSearchMemberList(PushChatMember pushChatMember) {
        logger.info("selectSearchMemberList");
        return this.getSqlSession().selectList("PUSHCHAT_MEMBER.selectSearchMemberList", pushChatMember);
    }

    /**
     * 비밀 번호를 수정 한다.
     *
     * @param pushChatMember
     */
    @Override
    public void updatePassword(PushChatMember pushChatMember) {
        logger.info("updatePassword");
        this.getSqlSession().update("PUSHCHAT_MEMBER.updatePassword", pushChatMember);
    }

    /**
     * 멤버 일반 정보를 수정 한다.
     *
     * @param pushChatMember
     */
    @Override
    public void updateMemberInformation(PushChatMember pushChatMember) {
        logger.info("updateMemberInformation");
        this.getSqlSession().update("PUSHCHAT_MEMBER.updateMemberInformation", pushChatMember);
    }

    /**
     * 닉네임 중복 확인을 한다.
     *
     * @param pushChatMember
     * @return
     */
    @Override
    public PushChatMember selectDuplicationNickName(PushChatMember pushChatMember) {
        logger.info("selectDuplicationNickName");
        return (PushChatMember)this.getSqlSession().selectOne("PUSHCHAT_MEMBER.selectDuplicationNickName", pushChatMember);
    }
}
